<%@ page import="server.GameServer" %>
<%@ page import="net.sf.json.JSONArray" %>
<%@ page import="net.sf.json.JSONObject" %>
<%@ page import="java.util.LinkedHashMap" %>
<%@ page import="config.ApplicationConfig" %><%--
  Created by IntelliJ IDEA.
  User: tum0r
  Date: 2019-04-17
  Time: 14:58
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>提交动态</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/bootstrap.min.css">
</head>
<body>

<%
    LinkedHashMap<String, String> pageConfig = ApplicationConfig.readConfig("page.json");
    request.setCharacterEncoding(pageConfig.get("encode"));
    response.setCharacterEncoding(pageConfig.get("encode"));
    response.addHeader("refresh", "3;URL=dynamic.jsp");
%>

<table class="table table-striped word_break">
    <tr>
        <td class="text-center"><b>序号</b></td>
        <td class="text-center"><b>提交者</b></td>
        <td class="text-center"><b>题目</b></td>
        <td class="text-center"><b>语言</b></td>
        <td class="text-center"><b>结果</b></td>
        <td class="text-center"><b>时间</b></td>
        <td class="text-center"><b>内存</b></td>
        <td class="text-center"><b>提交时间</b></td>
    </tr>
    <%
        GameServer gameServer = new GameServer();
        gameServer.open();
        JSONArray result = gameServer.getDynamicRecord(10);
        for (int i = 0; i < result.size(); i++) {
            JSONObject item = result.getJSONObject(i);
    %>
    <tr>
        <td class="text-center"><%=(i + 1)%>
        </td>
        <td class="text-center"><%=item.getString("user")%>
        </td>
        <td class="text-center"><%=item.getString("subject")%>
        </td>
        <td class="text-center"><%=item.getString("language")%>
        </td>
        <td class="text-center">
            <%
                String submitResult = item.getString("result");
                if (submitResult.equals("Accepted")) {
            %>
            <span class="btn btn-success"><%=submitResult%></span>
            <%
            } else if (submitResult.equals("Compilation Error") || submitResult.equals("Time Limit Exceeded") || submitResult.equals("Memory Limit Exceeded") || submitResult.equals("Presentation Error")) {
            %>
            <span class="btn btn-warning"><%=submitResult%></span>
            <%
            } else if (submitResult.equals("Compile...")||submitResult.equals("Running...")) {
            %>
            <span class="btn btn-info"><%=submitResult%></span>
            <%
            } else if (submitResult.equals("RunTime Error")) {
            %>
            <span class="btn btn-primary"><%=submitResult%></span>
            <%
            } else {
            %>
            <span class="btn btn-danger"><%=submitResult%></span>
            <%
                }
            %>
        </td>
        <td class="text-center"><%=item.getString("time")%> ms
        </td>
        <td class="text-center"><%=item.getString("memory")%> kb
        </td>
        <td class="text-center"><%=item.getString("submit_time")%>
        </td>
    </tr>
    <%
        }
        gameServer.close();
    %>
</table>
<br>
</body>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</html>
